import { Indexed, Model } from './t.ts'

class Node extends Model {
  table = 'node'

  handle(db) {
    const objectStore = db.createObjectStore(this.table, { keyPath: 'node_id' })
    objectStore.createIndex('parent', 'parent')
    objectStore.createIndex('nation', 'nation')
  }
}

const node = new Node()
// 注册数据库表
Indexed.register(node)
// 安装数据库
Indexed.install()
const proxy = new Proxy(Indexed, {
  get(target, p, receiver) {
    for (const item of target.instance.registeredDB) {
      if (item.table === p) {
        return item
      }
    }
  }
})
// proxy.node.create({node_id: 1, parent: 0, nation: 1})

proxy.node.find(1).then(res => console.log(res))
